<?php

namespace App\Models;

use App\Models\VoiceSearchMusic;


class VoiceSearch
{
    // mainActivity,activity,action,broadcast,service,url

    static function getPregMatchs()
    {
        return [
            '/打开QQ音乐$/' => ["VoiceSearchMusic", "openHome"],
            '/打开音乐$/' => ["VoiceSearchMusic", "openHome"],
            '/打开音乐排行榜$/' => ["VoiceSearchMusic", 'openTops'],
            '/最新歌曲$/' => ["VoiceSearchMusic", 'openNewes'],
            '/热门歌手$/' => ["VoiceSearchMusic", 'openHotSingers'],
            '/电台$/' => ["VoiceSearchMusic", 'openRadios'],
            '/打开我的音乐$/' => ["VoiceSearchMusic", 'openMyHome'],
            '/^我(要|想)听(\S+)/' => ["VoiceSearchMusic", 'searchByKeyword'],
            '/我最近听过的歌$/' => ["VoiceSearchMusic", 'openMyHistroys'],
            '/全部歌单$/' => ["VoiceSearchMusic", 'openAllPlaylist'],

            '/热播节目$/' => ['VoiceSearchChannel', 'hots'],
            '/热门综艺节目$/' => ['VoiceSearchVod', 'getVarietyHots'],
            '/热门电视剧$/' => ['VoiceSearchVod', 'getTvHots'],
            '/热门电影$/' => ['VoiceSearchVod', 'getMovieHots'],
            '/热门动漫$/' => ['VoiceSearchVod', 'getCrtoonHots'],
            '/热门记录片$/' => ['VoiceSearchVod', 'getDocHots'],
            '/^我(要|想)看(\S+)频道$/' => ["VoiceSearchChannel", "search"],
            '/^我(要|想)看(\S+)第(\S+)(集|期)/' => ['VoiceSearchVod', 'searchVideo'],
            '/^我(要|想)看(\S+)/' => ["VoiceSearchVod", "searchTVAndVod"],
            '/^我(要|想)打开(\S+)/' => ['VoiceSearchApp', "search"],
            '/^我(要|想)安装(\S+)/' => ['VoiceSearchApp', "search"],

            '/今天天气/' => ['VoiceSearchWeather', "today"],
            '/明天天气/' => ['VoiceSearchWeather', "tomorrow"],
            '/后天天气/' => ['VoiceSearchWeather', "afterTomorrow"],
            '/周(一|二|三|四|五|六|日|1-6)天气/' => ['VoiceSearchWeather', "searchDay"],
            '/(\S+)天气/' => ['VoiceSearchWeather', 'searchCity'],
        ];
    }

    static function search($text)
    {
        $pregMatchs = self::getPregMatchs();
        foreach ($pregMatchs as $pregMatch => $functions) {
            if (preg_match($pregMatch, $text, $matches)) {
                $class = app()->make($functions[0]);
                $function = $functions[1];
                return $class->$function($text, $matches);
            }
        }
        return [
            'status' => 1002,
            'message' => '没有找到你想要的结果!',
        ];
    }


}
